package com.zyn.integral.router;

import com.zyn.integral.entity.Cars;
import com.zyn.integral.service.ShoppingCarsServer;

import org.apache.ibatis.annotations.Insert;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.ws.soap.Addressing;
import java.util.List;

/**
 * @author zhangyanan
 * @description
 * @date 2017/11/15 0015 23:49
 */
@RestController
public class ShoppingCarRouter {
 private Logger log = LogManager.getLogger("ShoppingCarRouter");
    @Autowired
    private ShoppingCarsServer shoppingCarsServer ;
    @GetMapping("/shopping/cars")
    public List<Cars> selectCar(){
        log.info("-----begin------");
     return shoppingCarsServer.selectCar();
    }

    @PutMapping("/shopping/cars")
    public String insertCar(@RequestBody Cars cars){
        log.info("-----------------------");
        log.info(cars);
        try {
            shoppingCarsServer.addCar(cars);
            return "success";
        }catch (Exception e){
          e.printStackTrace();
        }
        return "fail";
    }
}
